﻿using System.Collections.Generic;
using System.Linq;

namespace MediaOwl.WebSearch.Data
{
    public class ImageFilters
    {
        public const char Divider = ':';
        public const string All = "All";

        public enum FilterTypes
        {
            Size, Aspect, Color, Style, Face
        }

        public const string SizePrefix = "Size";
        public const string AspectPrefix = "Aspect";
        public const string ColorPrefix = "Color";
        public const string StylePrefix = "Style";
        public const string FacePrefix = "Face";

        public static IList<string> Sizes = new List<string>(4){All, "Small", "Medium", "Large"};
        public static IList<string> Aspects = new List<string>(4) { All, "Square", "Wide", "Tall" };
        public static IList<string> Colors = new List<string>(3) { All, "Color", "Monochrome" };
        public static IList<string> Styles = new List<string>(3) { All, "Photo", "Graphics" };
        public static IList<string> Faces = new List<string>(4) { All, "Face", "Portrait", "Other" };

        internal static string GetFilter(string option, FilterTypes type)
        {
            if (string.IsNullOrEmpty(option) || option == All)
                return null;

            switch (type)
            {
                case FilterTypes.Size:
                    return SizePrefix + Divider + option;
                case FilterTypes.Aspect:
                    return AspectPrefix + Divider + option;
                case FilterTypes.Color:
                    return ColorPrefix + Divider + option;
                case FilterTypes.Style:
                    return StylePrefix + Divider + option;
                case FilterTypes.Face:
                    return FacePrefix + Divider + option;
            }
            return null;
        }

        internal static string[] GetFilter(string size, string aspect, string color, string style, string face)
        {
            if (size == All && aspect == All && color == All && style == All && face == All)
                return null;

            var sa = new[]
                         {
                             GetFilter(size, FilterTypes.Size),
                             GetFilter(aspect, FilterTypes.Aspect),
                             GetFilter(color, FilterTypes.Color),
                             GetFilter(style, FilterTypes.Style),
                             GetFilter(face, FilterTypes.Face)
                         };

            return sa.Where(x => !string.IsNullOrEmpty(x)).ToArray();
        }
    }
}